﻿#include "FrameMgr.h"

FrameMgr::FrameMgr()
{
}


FrameMgr::~FrameMgr()
{
	if (_frames.count() != 0)
		_frames.clear();
}

void FrameMgr::appendFrame(IGBTProtocol::BaseFrame* frame)
{
	_mutex.lock();
	_frames.push_back(frame);
	_mutex.unlock();
}

IGBTProtocol::BaseFrame* FrameMgr::getOldestFrame()
{
    IGBTProtocol::BaseFrame* frame = NULL;
	_mutex.lock();
	if (_frames.count() != 0)
	{
		frame = _frames.at(0);
		_frames.pop_front();
	}
	_mutex.unlock();

	return frame;
}
void FrameMgr::clear()
{
    QVector<IGBTProtocol::BaseFrame*>::iterator it = _frames.begin();
	while (it != _frames.end())
	{
		delete (*it);
		it++;
	}

	_frames.clear();
}
